package Presentacion.Divisa;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;

import Logica.Divisa.ABMDivisaLogica;
import Logica.Util.CalendarioPicker;

import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;

public class panelGrilla extends JPanel {
	public JButton btnCancelar, btnAceptar;
	public JTable tabla;
	public JScrollPane scroll;
	public DefaultTableModel model;
	
	
	/**
	 * Create the panel.
	 * 
	 * private String moneda;
	private String simbolo;
	private Double oficial;
	private Double paraleo;
	private Date fechaModificacion;
	private String predefinida;
	 */
	public panelGrilla() {
		setLayout(null);
		
		btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cancelar();
			}
		});
		btnCancelar.setBounds(351, 250, 89, 23);
		add(btnCancelar);
		
		btnAceptar = new JButton("Aceptar");
		btnAceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				aceptar();
			}
		});
		btnAceptar.setBounds(252, 250, 89, 23);
		add(btnAceptar);
		
		scroll = new JScrollPane();
		scroll.setBounds(10, 11, 430, 165);
		add(scroll);
		
		tabla = new JTable();
		scroll.setViewportView(tabla);
//		tabla.setModel(new DefaultTableModel(
//			new Object[][] {
//				{null, null, null, null, null, null},
//				{null, null, null, null, null, null},
//				{null, null, null, null, null, null},
//				{null, null, null, null, null, null},
//			},
//			new String[] {
//				"Moneda", "Simbolo", "V.Oficial", "V.Paralelo", "Fecha Mod.", "Predefinida"
//			}
//		) {
//			Class[] columnTypes = new Class[] {
//				String.class, Object.class, Object.class, Object.class, Object.class, Object.class
//			};
//			public Class getColumnClass(int columnIndex) {
//				return columnTypes[columnIndex];
//			}
//		});
//		tabla.getColumnModel().getColumn(0).setPreferredWidth(180);
//		tabla.getColumnModel().getColumn(4).setPreferredWidth(100);
		this.initTabla();

	}
	
	
	
	public void initTabla(){
		model = new DefaultTableModel(
				new Object[][] {
						{null, null, null, null, null, null},
						{null, null, null, null, null, null},
						{null, null, null, null, null, null},
						{null, null, null, null, null, null},
					},
					new String[] {
						"Moneda", "Simbolo", "V.Oficial", "V.Paralelo", "Fecha Mod.", "Predefinida"
					}
				) {
					Class[] columnTypes = new Class[] {
						String.class, Object.class, Object.class, Object.class, Object.class, Object.class
					};
					public Class getColumnClass(int columnIndex) {
						return columnTypes[columnIndex];
					}
				};
		tabla.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
				{null, null, null, null, null, null},
			},
			new String[] {
				"Moneda", "Simbolo", "V.Oficial", "V.Paralelo", "Fecha Mod.", "Predefinida"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class, Object.class, Object.class, Object.class, Object.class, Object.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		tabla.getColumnModel().getColumn(0).setPreferredWidth(100);
		tabla.getColumnModel().getColumn(4).setPreferredWidth(100);
		
	}
	public void cancelar(){
		
	}
	
	public void aceptar(){
		System.out.println("ACEPTAR");
		int seleccion = tabla.getSelectedRow();
		if (seleccion != -1) {
			int id;
			id = (int) tabla.getValueAt(seleccion, 0);
			
			Modelo.Divisa c = ABMDivisaLogica.getById(id);		
			
//			this.obj.init(c.getId());
//			cerrar();
			}
		else{
			JFrame frame = new JFrame();
            JOptionPane.showMessageDialog(frame, 
            		"*  Debe seleccionar una moneda", "Error", 
            		JOptionPane.WARNING_MESSAGE);
			}
	}
}
